package net.pulseproject.router.app;

import javax.swing.JOptionPane;

import net.pulseproject.router.app.misc.MainPresenter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;

public class RouterApp {

	private static final Log LOG = LogFactory.getLog(RouterApp.class);
	
	private final MainPresenter presenter;
	
	// TODO @log4j: use maven filtering for "stdout" vs "stdout, rolling" or: development vs release profile!
	public static void main(final String[] args) {
		LOG.info("Starting up application ...");
		
		try {
			final Injector injector = Guice.createInjector(new RouterAppGuiceModule());
			final RouterApp app = injector.getInstance(RouterApp.class);
			app.startUp();
		} catch(final Exception e) {
			LOG.error("Application startup failed!", e);
			JOptionPane.showMessageDialog(null, e.getClass().getSimpleName() + ": " + e.getMessage(),
					"Application startup failed!", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	@Inject
	public RouterApp(final MainPresenter presenter) {
		this.presenter = presenter;
	}
	
	public final void startUp() {
		LOG.debug("startUp()");
		this.presenter.startUp();
	}
	
	public final void quit() {
		LOG.debug("quit()");
		this.presenter.quit();
	}

}
